<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>我的推荐码</title>
    <script src="https://cdn.tailwindcss.com/3.3.3"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css">
    <script src="https://cdn.jsdelivr.net/npm/qrcode@1.5.3/build/qrcode.min.js"></script>
    <style>
        body {
            font-family: 'PingFang SC', 'Helvetica Neue', Arial, sans-serif;
            background-color: #f5f5f5;
            color: #333;
            max-width: 750px;
            margin: 0 auto;
        }
        .gradient-bg {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-shadow {
            box-shadow: 0 4px 20px rgba(0,0,0,0.1);
        }
        .pulse-animation {
            animation: pulse 2s infinite;
        }
        @keyframes pulse {
            0% { transform: scale(1); }
            50% { transform: scale(1.05); }
            100% { transform: scale(1); }
        }
        .copy-success {
            background-color: #10b981;
            color: white;
        }
        .share-btn {
            transition: all 0.3s ease;
        }
        .share-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 25px rgba(0,0,0,0.15);
        }
    </style>
</head>
<body class="min-h-screen bg-gray-50">
    <!-- 顶部导航 -->
    <div class="header flex items-center justify-between px-4 py-3">
        <button class="text-gray-600" onclick="history.back()">
            <i class="fas fa-chevron-left text-lg"></i>
        </button>
        <h1 class="text-lg font-medium">我的推荐码</h1>
        <div class="w-6"></div> <!-- 占位保持对称 -->
    </div>

    <div class="px-4 mt-4">
        <!-- 推荐码卡片 -->
        <div class="bg-white rounded-2xl card-shadow p-6 mb-6">
            <div class="text-center">
                <div class="w-20 h-20 bg-gradient-to-r from-pink-400 to-purple-500 rounded-full flex items-center justify-center mx-auto mb-4">
                    <i class="fas fa-gift text-white text-2xl"></i>
                </div>
                <h2 class="text-2xl font-bold text-gray-800 mb-2">邀请好友，共享福利</h2>
                <p class="text-gray-600 mb-6">分享你的专属推荐码，好友注册成功后你们都能获得奖励</p>
                
                <!-- 推荐码展示 -->
                <div class="bg-gradient-to-r from-indigo-50 to-purple-50 rounded-xl p-4 mb-4">
                    <p class="text-sm text-gray-600 mb-2">我的推荐码</p>
                    <div class="flex items-center justify-center">
                        <span id="referralCode" class="text-3xl font-bold text-indigo-600 tracking-wider">HM8888</span>
                        <button onclick="copyCode()" id="copyBtn" class="ml-3 bg-indigo-500 hover:bg-indigo-600 text-white px-4 py-2 rounded-lg text-sm transition-all duration-200">
                            <i class="fas fa-copy mr-1"></i>
                            复制
                        </button>
                    </div>
                </div>

                <!-- 二维码区域 -->
                <div class="bg-white border-2 border-dashed border-gray-200 rounded-xl p-6 mb-6">
                    <p class="text-sm text-gray-600 mb-4">扫码注册</p>
                    <div class="flex justify-center mb-4">
                        <canvas id="qrcode" class="border border-gray-200 rounded-lg"></canvas>
                    </div>
                    <p class="text-xs text-gray-500">好友扫描此二维码即可使用你的推荐码注册</p>
                </div>
            </div>
        </div>

        <!-- 奖励说明 -->
        <div class="bg-white rounded-2xl card-shadow p-6 mb-6">
            <h3 class="text-lg font-bold text-gray-800 mb-4 flex items-center">
                <i class="fas fa-star text-yellow-500 mr-2"></i>
                推荐奖励
            </h3>
            <div class="space-y-4">
                <div class="flex items-center p-3 bg-green-50 rounded-lg">
                    <div class="w-10 h-10 bg-green-100 rounded-full flex items-center justify-center mr-3">
                        <i class="fas fa-user-plus text-green-600"></i>
                    </div>
                    <div>
                        <p class="font-medium text-gray-800">好友注册成功</p>
                        <p class="text-sm text-gray-600">你获得 <span class="text-green-600 font-bold">50积分</span></p>
                    </div>
                </div>
                <div class="flex items-center p-3 bg-blue-50 rounded-lg">
                    <div class="w-10 h-10 bg-blue-100 rounded-full flex items-center justify-center mr-3">
                        <i class="fas fa-shopping-cart text-blue-600"></i>
                    </div>
                    <div>
                        <p class="font-medium text-gray-800">好友首次下单</p>
                        <p class="text-sm text-gray-600">你获得 <span class="text-blue-600 font-bold">10元红包</span></p>
                    </div>
                </div>
                <div class="flex items-center p-3 bg-purple-50 rounded-lg">
                    <div class="w-10 h-10 bg-purple-100 rounded-full flex items-center justify-center mr-3">
                        <i class="fas fa-crown text-purple-600"></i>
                    </div>
                    <div>
                        <p class="font-medium text-gray-800">好友成为会员</p>
                        <p class="text-sm text-gray-600">你获得 <span class="text-purple-600 font-bold">30天会员</span></p>
                    </div>
                </div>
            </div>
        </div>

        <!-- 分享按钮 -->
       
        <!-- 我的推荐记录 -->
        <!-- <div class="bg-white rounded-2xl card-shadow p-6 mb-20">
            <div class="flex items-center justify-between mb-4">
                <h3 class="text-lg font-bold text-gray-800 flex items-center">
                    <i class="fas fa-users text-indigo-500 mr-2"></i>
                    推荐记录
                </h3>
                <span class="text-sm text-gray-500">共推荐 <span class="text-indigo-600 font-bold">12</span> 人</span>
            </div>
            <div class="space-y-3">
                <div class="flex items-center justify-between p-3 bg-gray-50 rounded-lg">
                    <div class="flex items-center">
                        <img src="https://s.coze.cn/image/s8yxPtYjlt8/" class="w-10 h-10 rounded-full mr-3">
                        <div>
                            <p class="font-medium text-gray-800">李**</p>
                            <p class="text-sm text-gray-500">2024-01-15 注册</p>
                        </div>
                    </div>
                    <span class="text-green-600 text-sm font-medium">+50积分</span>
                </div>
                <div class="flex items-center justify-between p-3 bg-gray-50 rounded-lg">
                    <div class="flex items-center">
                        <img src="https://s.coze.cn/image/s8yxPtYjlt8/" class="w-10 h-10 rounded-full mr-3">
                        <div>
                            <p class="font-medium text-gray-800">王**</p>
                            <p class="text-sm text-gray-500">2024-01-12 注册</p>
                        </div>
                    </div>
                    <span class="text-blue-600 text-sm font-medium">+10元红包</span>
                </div>
                <div class="flex items-center justify-between p-3 bg-gray-50 rounded-lg">
                    <div class="flex items-center">
                        <img src="https://s.coze.cn/image/s8yxPtYjlt8/" class="w-10 h-10 rounded-full mr-3">
                        <div>
                            <p class="font-medium text-gray-800">张**</p>
                            <p class="text-sm text-gray-500">2024-01-10 注册</p>
                        </div>
                    </div>
                    <span class="text-purple-600 text-sm font-medium">+30天会员</span>
                </div>
            </div>
            <button class="w-full mt-4 text-indigo-600 text-sm font-medium py-2">
                查看更多记录 <i class="fas fa-chevron-right ml-1"></i>
            </button>
        </div> -->
    </div>

    <script>
        // 生成二维码
        function generateQRCode() {
            const canvas = document.getElementById('qrcode');
            const referralCode = document.getElementById('referralCode').textContent;
            const shareUrl = `https://your-app.com/register?code=${referralCode}`;
            
            QRCode.toCanvas(canvas, shareUrl, {
                width: 200,
                height: 200,
                colorDark: '#4f46e5',
                colorLight: '#ffffff',
                margin: 2,
                errorCorrectionLevel: 'M'
            }, function (error) {
                if (error) console.error(error);
            });
        }

        // 复制推荐码
        function copyCode() {
            const code = document.getElementById('referralCode').textContent;
            const copyBtn = document.getElementById('copyBtn');
            
            navigator.clipboard.writeText(code).then(function() {
                copyBtn.innerHTML = '<i class="fas fa-check mr-1"></i>已复制';
                copyBtn.classList.remove('bg-indigo-500', 'hover:bg-indigo-600');
                copyBtn.classList.add('copy-success');
                
                setTimeout(() => {
                    copyBtn.innerHTML = '<i class="fas fa-copy mr-1"></i>复制';
                    copyBtn.classList.remove('copy-success');
                    copyBtn.classList.add('bg-indigo-500', 'hover:bg-indigo-600');
                }, 2000);
            }).catch(function(err) {
                console.error('复制失败: ', err);
                // 降级方案
                const textArea = document.createElement('textarea');
                textArea.value = code;
                document.body.appendChild(textArea);
                textArea.select();
                document.execCommand('copy');
                document.body.removeChild(textArea);
                
                copyBtn.innerHTML = '<i class="fas fa-check mr-1"></i>已复制';
                copyBtn.classList.remove('bg-indigo-500', 'hover:bg-indigo-600');
                copyBtn.classList.add('copy-success');
                
                setTimeout(() => {
                    copyBtn.innerHTML = '<i class="fas fa-copy mr-1"></i>复制';
                    copyBtn.classList.remove('copy-success');
                    copyBtn.classList.add('bg-indigo-500', 'hover:bg-indigo-600');
                }, 2000);
            });
        }

        // 分享到微信
        function shareToWechat() {
            const code = document.getElementById('referralCode').textContent;
            const shareText = `我在家政小程序发现了很棒的服务，快来用我的推荐码 ${code} 注册吧！我们都能获得奖励哦~`;
            
            // 这里需要调用微信小程序的分享API
            if (typeof wx !== 'undefined') {
                wx.showShareMenu({
                    withShareTicket: true,
                    menus: ['shareAppMessage']
                });
            } else {
                // 网页版降级处理
                alert('请在微信中打开此页面进行分享');
            }
        }

        // 分享到朋友圈
        function shareToMoments() {
            const code = document.getElementById('referralCode').textContent;
            const shareText = `发现了一个很棒的家政服务小程序，用我的推荐码 ${code} 注册还有奖励！`;
            
            if (typeof wx !== 'undefined') {
                wx.showShareMenu({
                    withShareTicket: true,
                    menus: ['shareTimeline']
                });
            } else {
                alert('请在微信中打开此页面进行分享');
            }
        }

        // 保存二维码
        function saveQRCode() {
            const canvas = document.getElementById('qrcode');
            const link = document.createElement('a');
            link.download = '我的推荐码.png';
            link.href = canvas.toDataURL();
            link.click();
        }

        // 更多分享选项
        function shareMore() {
            const code = document.getElementById('referralCode').textContent;
            const shareText = `我在家政小程序发现了很棒的服务，快来用我的推荐码 ${code} 注册吧！`;
            const shareUrl = `https://your-app.com/register?code=${code}`;
            
            if (navigator.share) {
                navigator.share({
                    title: '家政小程序推荐',
                    text: shareText,
                    url: shareUrl
                });
            } else {
                // 降级方案：复制链接
                navigator.clipboard.writeText(`${shareText} ${shareUrl}`).then(() => {
                    alert('分享内容已复制到剪贴板');
                });
            }
        }

        // 页面加载完成后生成二维码
        document.addEventListener('DOMContentLoaded', function() {
            generateQRCode();
        });
    </script>
</body>
</html>